package me.zogodo;

import com.sun.rowset.CachedRowSetImpl;

import java.sql.SQLException;

/**
 * Created by zogod on 2017/1/14.
 */
public class User
{
    public int id;
    public String username;
    public String password;
    public String img_path;
    SqlHelper sh = new SqlHelper();

    public User(String username) throws SQLException
    {
        CachedRowSetImpl crs = sh.Select(
                "select id, username, password, img from admin where username='"
                    + username + "'");
        if (crs == null || !crs.next())
        {
            //System.exit(1);
            return;
        }
        this.id = crs.getInt(1);
        this.username = crs.getString(2);
        this.password = crs.getString(3);
        this.img_path = crs.getString(4);
    }

    public boolean LogIn(String paw)
    {
        return paw == this.password;
    }

    public void UploadImg(String img_path)
    {
        this.img_path = img_path;
        sh.NoneQuery("update admin set img='"+img_path+"' where username='"
                + this.username + "'");
    }
}
